package com.leoman.plz_p.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import com.leoman.plz_p.R;
import com.leoman.plz_p.module.bean.BookListBean;

import cn.com.corelib.utils.adapter.BaseAdapterHelper;
import cn.com.corelib.utils.adapter.normal.QuickAdapter;

/**
 * Created by guoh on 2018/7/15.
 */
public class ClassAdapter extends QuickAdapter<BookListBean> {

    private PointAdapter adapter;

    public ClassAdapter(Context context) {
        super(context, R.layout.item_class);
    }

    @Override
    protected void convert(final BaseAdapterHelper helper, final BookListBean item, final int position) {

        switch (item.getStatus()){
            case 1:
                helper.setBackgroundRes(R.id.iv_project_progress,R.mipmap.icon_zero_to_four);
                break;
            case 2:
                helper.setBackgroundRes(R.id.iv_project_progress,R.mipmap.icon_one_to_one);
                break;
        }

        helper.setText(R.id.tv_project_name, item.getName());
        if (TextUtils.isEmpty(item.getLevelName())){
            helper.setVisible(R.id.tv_title_level,false);
        }else {
            helper.setText(R.id.tv_title_level, TextUtils.isEmpty(item.getLevelName()) ? "" : "级别 " + item.getLevelName());
        }
        adapter=new PointAdapter(context);
        adapter.replaceAll(item.getList());
        helper.setAdapter(R.id.ls_point,adapter);

        helper.getView(R.id.iv_project_open).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                item.setShowList(!item.isShowList());
                notifyDataSetChanged();
            }
        });
        if (item.isShowList()){
            helper.setVisible(R.id.ls_point,true);
            helper.setVisible(R.id.ll_skill_layout,true);
        }else {
            helper.setVisible(R.id.ls_point,false);
            helper.setVisible(R.id.ll_skill_layout,false);
        }

        if (helper.getView(R.id.ls_point).getVisibility()==View.VISIBLE){
            helper.setBackgroundRes(R.id.iv_project_open,R.mipmap.icon_up_gary);
        }else {
            helper.setBackgroundRes(R.id.iv_project_open,R.mipmap.icon_down_gary);
        }

        helper.setTag(R.id.tv_safe,position).setTag(R.id.tv_request,position)
                .setOnClickListener(R.id.tv_safe, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (onItemClick!=null){
                            onItemClick.onSafeClick(Integer.parseInt(view.getTag().toString()));
                        }
                    }
                }).setOnClickListener(R.id.tv_request, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onItemClick!=null){
                    onItemClick.onRequestClick(Integer.parseInt(view.getTag().toString()));
                }
            }
        });

        switch (item.getSafety()){
            //安全技术(富文本) 1显示按钮（灰色） 2不显示3显示已点击（蓝色）
            case "1":
//                helper.setBackgroundRes(R.id.tv_safe,R.drawable.class_off_style);
                helper.setVisible(R.id.ll_skill_safe_layout,true);
                break;
            case "2":
                helper.setVisible(R.id.ll_skill_safe_layout,false);
                break;
            case "3":
//                helper.setBackgroundRes(R.id.tv_safe,R.drawable.class_on_style);
                helper.setVisible(R.id.ll_skill_safe_layout,true);
                break;
        }
        switch (item.getTechnology()){
            //技术要求(富文本)1显示按钮（灰色） 2不显示3显示已点击（蓝色）
            case "1":
//                helper.setBackgroundRes(R.id.tv_request,R.drawable.class_off_style);
                helper.setVisible(R.id.ll_skill_need_layout,true);
                break;
            case "2":
                helper.setVisible(R.id.ll_skill_need_layout,false);
                break;
            case "3":
//                helper.setBackgroundRes(R.id.tv_request,R.drawable.class_on_style);
                helper.setVisible(R.id.ll_skill_need_layout,true);
                break;
        }

        adapter.setOnItemClick(new PointAdapter.onItemClick() {
            @Override
            public void onVideoClick(int child) {
                if (onItemClick!=null){
                    onItemClick.onVideoClick(position,child);
                }
            }

            @Override
            public void onExamClick(int child) {
                if (onItemClick!=null){
                    onItemClick.onExamClick(position,child);
                }
            }

            @Override
            public void onTestClick(int child) {
                if (onItemClick!=null){
                    onItemClick.onTestClick(position,child);
                }
            }
        });


    }


    public void setOnItemClick(onItemClick onItemClick) {
        this.onItemClick = onItemClick;
    }

    private onItemClick onItemClick;

    public interface onItemClick{
        void onSafeClick(int position);
        void onRequestClick(int position);
        void onVideoClick(int parent, int child);
        void onExamClick(int parent, int child);
        void onTestClick(int parent, int child);
    }
}

